import matplotlib
import numpy as np
from matplotlib import pyplot as plt, axes, font_manager
import random
import time

Zh_Font = matplotlib.font_manager.FontProperties(fname="../venv/include/SourceHanSansSC-Bold.otf")
n = 3000
x1 = []
y1 = []
for _ in range(3000):
    x1.append(random.randint(1, 100))
    y1.append(random.randint(1, 100))
x1.sort()
y1.sort(reverse=True)
plt.figure(figsize=(10, 8))  # 在循环外部创建一个fig对象，循环利用
plt.clf()
x = []
y = []
for i in range(25):
    time.sleep(0.2)
    print(i)
    x = []
    y = []
    # 画图
    for j in range(i*100):
        x.append(x1[j])
        y.append(y1[j])
    plt.plot(x, y)
    # 标题、坐标轴步长、坐标轴标题
    plt.title("12", fontsize=15, fontproperties=Zh_Font)
    plt.xticks(np.arange(0, 101, 10), fontsize=15, fontproperties=Zh_Font)
    plt.yticks(np.arange(0, 101, 10), fontsize=15, fontproperties=Zh_Font)
    plt.xlabel("种群进化代数", fontsize=15, fontproperties=Zh_Font)
    plt.ylabel("平均适应度函数", fontsize=15, fontproperties=Zh_Font)
    # 展示
    plt.show()
    plt.clf()
